$(function(){
	$("table tbody tr").on("click", function(){
		var titulo = $("table").parent("[id^=tabela]").parent().prev().prev().text();
		titulo = "Dados d" + titulo.charAt(titulo.length - 2) + " " + titulo.substring(0, titulo.length - 1);
		var html =  "<h3>" + titulo + "</h3><ul>";
		var nomeCampo = "";
		var valor = "";

		for(var i = 0; i < $(this).find("td").length; i++){
			nomeCampo = $(this).parent().parent().find("th div span:eq(" + i + ")").text();
			tagSpan = $(this).find("td div span:eq(" + i + ")");
			
			if($(tagSpan).text() != "" && $(tagSpan).text().indexOf("Check-out") < 0)
				valor = $(this).find("td div span:eq(" + i + ")").text();
			else if($(this).find("td div span:eq(" + i + ") a"))
				valor = $(this).find("td div span:eq(" + i + ")").html();
			else
				valor = "Não cadastrado.";
			
			
			valor = valor.replace(new RegExp("\n","gm"), "<br />");
			
			html += "<div>" +
						"<li class='th'>" + nomeCampo + ":</li>" +
						"<li class='td'>" + valor + "</li>" +
					"</div>";
		}
		
		html += "</ul>";
		
		detalhesQuarto(html);
	});				
});

function detalhesQuarto(html){
	$.modal(html,
		{
			containerCss:{
			width: "36.5%",
			height: "37%"
		},
		overlayClose:true
	});
}